/**************************************************************************
 *         Copyright(c) 2008 by Sunplus mMedia  Technology Co., Ltd.      *
 *                                                                        *
 *  This software is copyrighted by and is the property of Sunplus mMedia *
 *  Technology Co., Ltd. All rights are reserved by Sunplus mMedia Techno-*
 *  logy Co., Ltd. This software may only be used in accordance with the  *
 *  corresponding license agreement. Any unauthorized use, duplication,   *
 *  distribution, or disclosure of this software is expressly forbidden.  *
 *                                                                        *
 *  This Copyright notice "M U S T" not be removed or modified without    *
 *  prior written consent of Sunplus mMedia Technology  Co., Ltd.         *
 *                                                                        *
 *  Sunplus mMedia Technology Co., Ltd. reserves the right to modify this *
 *  software without notice.                                              *
 *                                                                        *
 *  Sunplus mMedia Technology Co., Ltd.                                   *
 *  19-1, Innovation First Road, Science-Based Industrial Park,           *
 *  Hsin-Chu, Taiwan, R.O.C.                                              *
 *                                                                        *
 *  Author: Ted Chiu                                                      *
 **************************************************************************/
#include "general.h"
#include "disp_api.h"

/* R3, bit 2:0 */
#define	A015AN04_SEL_051			0x0
#define	A015AN04_SEL_052			0x1

void dispSpiCtrl(UINT32 InputData, UINT8 BitLength, UINT8 LowBitFirst);

UINT8 A015AN04_Color[4] = { 0x08, 0x0D, 0x0B, 0x05 };

//=============================================================================
//dispA015AN02Set()
//=============================================================================

void A015AN04_Init(UINT8 mode) 
{
	UINT8 sel = 0;
	dispPreInit();
	dispSyncWidthSet(1,3);
	XBYTE[0x2D00] = mode & 0x0F;
	XBYTE[0x2D27] = 0x08;	//UPS interface output clock phase selection

	switch (mode) {
		case UPS051:
			dispPnlVhSet(360,262,59,21,280,220);
			dispClkDivSet(96, 16);
			//printf("%bx %bx %bx %bx\n", A015AN04_Color[0],A015AN04_Color[1],A015AN04_Color[2],A015AN04_Color[3]);
			XBYTE[0x2D26] = 0x08;
			//dispColorSet(8);
			sel = A015AN04_SEL_051;
			break;

		case UPS052:
			dispPnlVhSet(390,262,63,21,305,220);
			//dispClkPhaseSet(8);
			dispClkDivSet(96, 4);
			XBYTE[0x2D26] = 0x00;
			sel = A015AN04_SEL_052;
			break;
	}

	dispPostInit();
	dispEn(1);
	dispRegUpd();
	dispVsyncWait(DISP_SIGNAL_RISING);
	#if	1
	dispSpiCtrl(0x0001, 16, 0);
	dispSpiCtrl(0x2000 + sel, 16, 0);
	dispSpiCtrl(0x400C, 16, 0);
	dispSpiCtrl(0x6000 + sel, 16, 0);
	dispSpiCtrl(0x8006, 16, 0);
	#else
	dispSpiCtrl(0x55AAL, 16, 0);
	dispSpiCtrl(0xAA55L, 16, 0);
	dispSpiCtrl(0xA5A5L, 16, 0);
	dispSpiCtrl(0x5A5AL, 16, 0);
	#endif
}


void A015AN04_Flip(UINT8 mode) 
{
#if	0
	UINT32 regvalue = 0x0001;
	mode &= 0x03;
	if(mode & DISP_FLIP_H)	{	/* Left/Right Flipped */
		regvalue |= 0x02;
	}
	if(mode & DISP_FLIP_V)	{	/* Up/Down Flipped */
		regvalue &= ~0x01;
	}
	printf("mode=%bd reg=%04lx\n", mode, regvalue);
	dispSpiCtrl(regvalue, 16, 0);

	if((XBYTE[0x2D00] & 0x0F) == UPS051) {
		XBYTE[0x2D26] = A015AN04_Color[mode];
	}
#else
	mode = mode;
#endif
}

